/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 spell_actor_animation.cpp

	$Header: /heroes4/spell_actor_animation.cpp $

	$NoKeywords: $

 ************************************************************************/
// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "spell_actor_animation.h"

#include "battlefield.h"
#include "combat_actor.h"

// -----------------------------------------------------------------
// animation for sparks
// -----------------------------------------------------------------
t_spell_actor_animation::t_spell_actor_animation( t_battlefield& battlefield, t_combat_actor& actor,
												  t_combat_spell_ptr spell,
												  t_handler handler )
                  : t_counted_animation( battlefield ), m_actor( actor ),
				    t_counted_idle_processor( 1000 / actor.get_frames_per_second() )
{
	m_handler = handler;
	m_spell = spell;
}

// -----------------------------------------------------------------
// animation for sparks
// -----------------------------------------------------------------
void t_spell_actor_animation::on_idle()
{
	int frame = m_actor.get_current_frame_num();

	frame++;
	if (frame >= m_actor.get_frame_count())
	{
		t_idle_ptr ref = this;

		animation_ended();
		suspend_idle_processing();
		m_actor.set_animation( 0 );
		m_battlefield.remove_object( &m_actor );
		m_battlefield.update_state();
		return;
	}
	m_battlefield.set_current_frame_num( m_actor, frame );
	if (frame >= m_actor.get_key_frame( m_actor.get_current_action() ))
	{
		m_handler();
		m_handler = 0;
	}
};

